#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
string s, p;
int Next[N];
int dp[N], top;
char st[N];
void build_next() {
  int m = p.size();
  int t = -1;
  int i = 0;
  Next[0] = -1;
  while (i < m) {
    if (t < 0 || p[i] == p[t]) {
      i++, t++;
      Next[i] = t;
    } else {
      t = Next[t];
    }
  }
}
void search() {
  int n = s.size(), m = p.size();
  int i = 0, j = 0;
  while (i < n) {
    if (j < 0 || s[i] == p[j]) {
      st[++top] = s[i];
      i++, j++;
      dp[top] = j;
      if (j == m) {
        top -= m;
        j = dp[top];
      }
    } else {
      j = Next[j];
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> p;
  build_next();
  search();
  rep(i, 1, top) cout << st[i];
  return 0;
}